package com.kay.annotation.dao;

import com.kay.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Description:
 * @Author: Kay
 * @CreateDate: 2021/6/27$ 10:29$
 * @UpdateUser: Kay
 * @UpdateDate: 2021/6/27$ 10:29$
 */
@CacheNamespace
public interface UserAnnotationMapper {
    @Insert(" insert into user values (#{id}, #{username},#{password},#{birthday})")
    void insertOne(User user);


//    @Options(useCache=false)
    // updateUsername 执行后不刷新二级缓存
    @Options(flushCache = Options.FlushCachePolicy.FALSE)
    @Update("update user set username = #{username} where id = #{id}")
    void updateUsername(User user);

    @Delete("delete from user where id = #{id}")
    void deleteById(Integer id);

    List<User> findByCondition(User user);

    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "username", property = "username"),
            @Result(column = "password", property = "password"),
            @Result(column = "birthday", property = "birthday"),
            @Result(column = "id", property = "orderList", javaType = List.class,
                    many = @Many(select = "com.kay.annotation.dao.OrderAnnotationMapper.findByUid"))
    })
    @Select("select * from user ")
    List<User> findAllUserOrderList();

    @Select("select * from user where id = #{id}")
    List<User> findById(Integer id);

    // findOneById 禁止使用二级缓存，每次查询将直接执行SQL从数据查找
    @Options(useCache = false)
    @Select("select * from user where id = #{id}")
    User findOneById(Integer id);

    List<User> findAllUserRoleList();

    List<User> findUserRoleListByIds(int[] ids);

}
